<?

//Data loading
$title='REPORT SHIPPING DOCUMENT';
$jo_id = GetParam("jo_id","");
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = 'PT. MASAJI PRAYASA CARGO';


$page   = 'PAGE';
$TableName = "tbljoborder";
$DEFINE_FONT=0;
$today = date("d/m/Y");
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = ReportList("", "", "");
if ($Result) $pdf->ReportTable($Result);
$pdf->Output();

function ReportList ($Space, $Index, $ParentID) {
     
     global $TableName, $jo_id, $DBGeneral;
     $DBConnection   = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
     if (!$Index) $Index = 0;
          
       $SQLProject = "SELECT a.*,b.*,c.*,d.*,e.*,f.*, f.nama as laks_name,
			       if(a.jo_appv_status = 'draft', 'Draft', if(a.jo_appv_status = 'wait_approved', 'Wait for Approval', if(a.jo_appv_status = 'approved', 'Approved', 'No Approval Status'))) as approval_status 
			       FROM `$TableName` as a ";
	   $SQLProject.= "JOIN tblproject as b ON a.project_id = b.project_id "; 
	   $SQLProject.= "JOIN ".$DBGeneral.".tblstaff as c ON a.staff_id = c.staff_id ";
	   $SQLProject.= "JOIN tbldebtur as d ON a.debtur = d.CUCODE ";
	   $SQLProject.= "JOIN tblshipping_doc as e ON a.jo_id = e.jo_id ";
	   $SQLProject.= "JOIN ".$DBGeneral.".tblstaff as f ON e.laks_cc = f.nik ";
	   $SQLProject.= "WHERE a.jo_id ='".$jo_id."' ";

	   $ResultProject  = $DBConnection->dbc->get_results($SQLProject,ARRAY_A);   
	     
       return $ResultProject;
}


class PDFReport extends PDF {

    function Header() {
        global $title,$perush,$page,$DEFINE_FONT,$today;
        if ($DEFINE_FONT==0) {
            $this->AddFont('arialn','','arialn.php');
            $DEFINE_FONT=1;
        }
        $this->SetFont('arialn','',12);
		$this->Cell(195,5,$perush,0,1,'C',0);
		$this->Cell(195,5,$title,0,1,'C',0);
		$SystemDate = date("d/m/Y");
		$this->Cell(195,5,"REPORT DATE: ".$today,0,1,'C',0);
		$this->Cell(195,5,$page." ".$this->PageNo(),0,1,'R',0);
		$this->Line(10,30,205,30);
		$this->Ln();
		$this->Ln();
                //Header
               
    }

    function ReportTable($Result) {
        
	    global $TableName, $jo_id, $DBGeneral;
	    $DBConnection   = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
	    
	    //Column widths
        $w=array(22,12,35,22,22,20,22,20,22,20);
                
        //echo "<pre>";
	    //print_r($Result);
	    
	    
	    //Counting Cargo

		$container_40 = 0;
		$container_20 = 0;
		$cargo_jumlah= 0;
		$cargo_berat = 0;
		$cargo_volume = 0;

		$SQLCargoCount = "SELECT * FROM tbljocargo 
						 WHERE jo_id ='".$jo_id."' ";

		$ResultCargoCount  = $DBConnection->dbc->get_results($SQLCargoCount,ARRAY_A);

		if(!empty($ResultCargoCount))
		{
		   
		   foreach($ResultCargoCount as $cargo_id => $cargo_val)
			{
				if($cargo_val['cargo_type'] == '3')
				 {
					$container_40+= intval($cargo_val['cargo_jumlah']); 
				 }
				 
				if($cargo_val['cargo_type'] == '4')
				 {
					$container_20+= intval($cargo_val['cargo_jumlah']); 
				 }
						 
				 $cargo_jumlah+= intval($cargo_val['cargo_jumlah']);
				 $cargo_berat+= intval($cargo_val['cargo_berat']); 
				 $cargo_volume+= intval($cargo_val['cargo_volume']);
				 
			}
			
		}

		else
		{
			$container_40 = 0;
			$container_20 = 0;
			$cargo_jumlah = 0;
			$cargo_berat = 0;
			$cargo_volume = 0;
		}


		//End Counting Cargo
	    
        
        //Data
        $this->Cell(100,7,"JOB ORDER: ".$Result[0]['jo_code'],0,0,'L',0);
		$this->Cell(100,7,"PELAKSANA CC: ".$Result[0]['laks_name'],0,0,'L',0);
		$this->Ln();		
		$this->Cell(100,7,"PROJECT : ".$Result[0]['project_name'],0,0,'L',0);
		$this->Cell(100,7,"ETD : ".$this->convertDate($Result[0]['etd']),0,0,'L',0);
		$this->Ln();
		$this->Cell(100,7,"CUSTOMER : ".$Result[0]['CUNAME'],0,0,'L',0);
		$this->Cell(100,7,"ETA : ".$this->convertDate($Result[0]['eta']),0,0,'L',0);
		$this->Ln();
		$this->Cell(100,7,"DOC RECEIVE FROM : ".$Result[0]['receive_from'],0,0,'L',0);
		$this->Cell(100,7,"GDG : ".$Result[0]['gdg'],0,0,'L',0);
		$this->Ln();
		$this->Cell(100,7,"VESSEL : ".$Result[0]['vessel']."   VOYAGE : ".$Result[0]['voy'],0,0,'L',0);
		$this->Cell(100,7,"LARTAS 1 : ".$Result[0]['lartas_1'],0,0,'L',0);
		$this->Ln();
        $this->Cell(100,7,"PORT OF LOADING : ".$Result[0]['port_loading'],0,0,'L',0);
		$this->Cell(100,7,"LARTAS 2 : ".$Result[0]['lartas_2'],0,0,'L',0);
		$this->Ln();
		$this->Cell(100,7,"CHARGES PORT : ".$Result[0]['charges_port'],0,0,'L',0);
		$this->Cell(100,7,"LARTAS 3 : ".$Result[0]['lartas_3'],0,0,'L',0);
		$this->Ln();
		$this->Cell(100,7,"DELIVERY SITE : ".$Result[0]['delivery_site'],0,0,'L',0);
		$this->Cell(100,7,"LARTAS 4 : ".$Result[0]['lartas_4'],0,0,'L',0);
		$this->Ln();
		$this->Cell(100,7,"BCII No. : ".$Result[0]['bcii_no'],0,0,'L',0);
		$this->Cell(100,7,"LARTAS 5 : ".$Result[0]['lartas_5'],0,0,'L',0);
		$this->Ln();
		$this->Cell(100,7,"No. AJU PIB : ".$Result[0]['no_aju_pib'],0,0,'L',0);
		$this->Ln();        
		$this->Ln();
        $this->Cell(45,8,"40 x ".$container_40." CONT",'LT',0,'C');
		$this->Cell(45,8,$cargo_jumlah." items",'LT',0,'C');
		$this->Cell(45,8,$cargo_berat." kgs",'LT',0,'C');
		$this->Cell(45,8,$cargo_volume." cbm",'LTR',0,'C');	
		$this->Ln();
		$this->Cell(45,8,"20 x ".$container_20." CONT",'LB',0,'C');
		$this->Cell(45,8," ",'LB',0,'C');
		$this->Cell(45,8," ",'LB',0,'C');
		$this->Cell(45,8," ",'LRB',0,'C');
		
		$this->Ln();
		$this->Ln();
		
		
		
		//LIST
				
		$this->Cell(110,7,"KETERANGAN ",'B',0,'C',0);
		$this->Cell(40,7,"ORIGINAL ",'B',0,'C',0);
		$this->Cell(40,7,"COPY ",'B',0,'C',0);
		$this->Ln();
		
		if(!empty($Result[0]['hawe_no']))
		{
			$this->Cell(110,7,"HAWE / MAWB NO. :".$Result[0]['hawe_no'],0,0,'L',0);
			$this->Cell(40,7,$Result[0]['hawe_no_ori'],0,0,'C',0);
			$this->Cell(40,7,$Result[0]['hawe_no_cpy'],0,0,'C',0);
			$this->Ln();
	    }
	    
	    if(!empty($Result[0]['bl_no']))
		{
			$this->Cell(110,7,"BL NO. :".$Result[0]['bl_no'],0,0,'L',0);
			$this->Cell(40,7,$Result[0]['bl_no_ori'],0,0,'C',0);
			$this->Cell(40,7,$Result[0]['bl_no_cpy'],0,0,'C',0);
			$this->Ln();
	    }
	    
	    if(!empty($Result[0]['invoice_no']))
		{
			$this->Cell(110,7,"INVOICE NO. :".$Result[0]['invoice_no'],0,0,'L',0);
			$this->Cell(40,7,$Result[0]['invoice_no_ori'],0,0,'C',0);
			$this->Cell(40,7,$Result[0]['invoice_no_cpy'],0,0,'C',0);
			$this->Ln();
	    }
	    
	    if(!empty($Result[0]['packing_list']))
		{
			$this->Cell(110,7,"PACKING LIST :".$Result[0]['packing_list'],0,0,'L',0);
			$this->Cell(40,7,$Result[0]['packing_list_ori'],0,0,'C',0);
			$this->Cell(40,7,$Result[0]['packing_list_cpy'],0,0,'C',0);
			$this->Ln();
	    }
	    
	    if(!empty($Result[0]['cert']))
		{
			$this->Cell(110,7,"CERTIFICATE OF ORIGIN :".$Result[0]['cert'],0,0,'L',0);
			$this->Cell(40,7,$Result[0]['cert_ori'],0,0,'C',0);
			$this->Cell(40,7,$Result[0]['cert_cpy'],0,0,'C',0);
			$this->Ln();
	    }
	    
	    if(!empty($Result[0]['insurance']))
		{
			$this->Cell(110,7,"INSURANCE :".$Result[0]['insurance'],0,0,'L',0);
			$this->Cell(40,7,$Result[0]['insurance_ori'],0,0,'C',0);
			$this->Cell(40,7,$Result[0]['insurance_cpy'],0,0,'C',0);
			$this->Ln();
	    }
	    
	    if(!empty($Result[0]['loa']))
		{
			$this->Cell(110,7,"LOA / SURAT DIGITAL :".$Result[0]['loa'],0,0,'L',0);
			$this->Cell(40,7,$Result[0]['loa_ori'],0,0,'C',0);
			$this->Cell(40,7,$Result[0]['loa_cpy'],0,0,'C',0);
			$this->Ln();
	    }
	    
	    if(!empty($Result[0]['stat_con']))
		{
			$this->Cell(110,7,"STATEMENT CONTR. :".$Result[0]['stat_con'],0,0,'L',0);
			$this->Cell(40,7,$Result[0]['stat_con_ori'],0,0,'C',0);
			$this->Cell(40,7,$Result[0]['stat_con_cpy'],0,0,'C',0);
			$this->Ln();
	    }
	    
	    if(!empty($Result[0]['recom_loa']))
		{
			$this->Cell(110,7,"RECOMMENDATION LOA :".$Result[0]['recom_loa'],0,0,'L',0);
			$this->Cell(40,7,$Result[0]['recom_loa_ori'],0,0,'C',0);
			$this->Cell(40,7,$Result[0]['recom_loa_cpy'],0,0,'C',0);
			$this->Ln();
	    }
	    
	    if(!empty($Result[0]['recom_lartas']))
		{
			$this->Cell(110,7,"RECOMMENDATION LARTAS :".$Result[0]['recom_lartas'],0,0,'L',0);
			$this->Cell(40,7,$Result[0]['recom_lartas_ori'],0,0,'C',0);
			$this->Cell(40,7,$Result[0]['recom_lartas_cpy'],0,0,'C',0);
			$this->Ln();
	    }
		
		$this->Ln();
		$this->Ln();
		
		
		$this->AddPage();
		
		$this->Cell(40,7,"DATE ",'B',0,'C',0);
		$this->Cell(40,7,"DAY ",'B',0,'C',0);
		$this->Cell(110,7,"REMARKS ",'B',0,'C',0);
		$this->Ln();
		
		$SQLRemarks = "SELECT * FROM tblshipping_doc_remarks 
					   WHERE jo_id ='".$jo_id."' ORDER BY remarks_id DESC ";

		$ResultRemarks  = $DBConnection->dbc->get_results($SQLRemarks,ARRAY_A);
		
		if(!empty($ResultRemarks))
		{
			
			foreach($ResultRemarks as $idx => $val)
			{
				$this->Cell(40,7,$val['date_remarks'],0,0,'C',0);
				$this->Cell(40,7,$val['day_remarks'],0,0,'C',0);
				$this->Cell(110,7,$val['text_remarks'],0,0,'C',0);
				$this->Ln();
			}
			
	    }
		
		

        //Closure line
        //$this->Cell(array_sum($w),0,'','T');
    }

    function Footer() {
        //$this->Cell(195,0,'','T');
    }
    
    
    function convertDate($dateIn)
    {
	    list($date,$purge) = explode(" ",$dateIn);
	    
        list($year,$month,$day) = explode("-",$date);
        $FDate = "$day-$month-$year";
        
        return $FDate;
    
	}
    

}


?>
